<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../vue.js"></script>
</head>

<body>
    <pre>
        侦听器：
        监听数据有没有改变，一旦数据改变就执行函数操作， 一般执行异步 或者 开销比较大的操作
    </pre>
    <div class="box">
        <div>{{name}}</div>
        <div>{{age}}</div>
        <button @click='change'>我点你</button>
    </div>
    <script>
        var vm = new Vue({
            el: '.box',
            data: {
                name: 1,
                age: 2,
            },
            methods: {
                change() {
                    this.name += 1
                    this.age += 2
                }
            },
            watch: {
                name: function(nameval) {
                    console.log(nameval)
                },
                age: function(ageval) {
                    console.log(ageval)
                }
            }
        })
    </script>
</body>

</html>